package com.ly.springsolrtest.springsolr.controller;
import com.ly.springsolrtest.springsolr.bo.ArticleBo;
import com.ly.springsolrtest.springsolr.service.ArticleBoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;


/**
 * 文章搜索controller层
 *
 * @param
 * @author linweijian
 * @date 2018/3/29 17:11
 * @return
 */
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    @Qualifier("articleBoClientServiceImpl")
    private ArticleBoService articleBoService;

    /**
     * 文章搜索
     *
     * @param keyword 关键字
     * @return java.lang.String
     * @author linweijian
     * @date 2018/3/29 17:12
     */
    @RequestMapping("/search/{keyword}")
    public String search(@PathVariable String keyword) {

        StringBuilder sb = new StringBuilder();
        List<ArticleBo> articleBoList = articleBoService.getHighlight(keyword, 0, 10);
        for (ArticleBo articleBo : articleBoList) {
            String content = articleBo.getContent();
            String name = articleBo.getName();
            sb.append("<p>");
            sb.append(name);
            sb.append("</p><br><p>");
            sb.append(content);
            sb.append("</p><hr/>");
        }
        return sb.toString();
    }

}
